package io.renren.modules.archive.service.impl;

import io.renren.modules.archive.dao.BgqxDao;
import io.renren.modules.archive.dao.MeetingDetailDao;
import io.renren.modules.archive.entity.ArchiveInfoEntity;
import io.renren.modules.archive.entity.BgqxEntity;
import io.renren.modules.archive.entity.MeetingDetailEntity;
import io.renren.modules.archive.entity.MeetingtypeEntity;
import io.renren.modules.archive.service.MeetingDetailService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;


@Service("meetingDetailService")
public class MeetingDetailServiceImpl extends ServiceImpl<MeetingDetailDao, MeetingDetailEntity> implements MeetingDetailService {
    @Autowired
    MeetingDetailDao meetingDetailDao;
    @Autowired
    BgqxDao bgqxDao;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        //根据文件名称查询
        String value = (String)params.get("key");
        String search = (String)params.get("search");
        String nd = (String)params.get("nd");
        String jg = (String)params.get("jg");
        String onesxlx = (String)params.get("onesxlx");
        String twosxlx = (String)params.get("twosxlx");
        String threesxlx = (String)params.get("threesxlx");
        String foursxlx = (String)params.get("foursxlx");

        IPage<MeetingDetailEntity> page = this.page(
                new Query<MeetingDetailEntity>().getPage(params),
                new QueryWrapper<MeetingDetailEntity>()
                        .like(StringUtils.isNotBlank(value),search, value)
                        .eq(StringUtils.isNotBlank(nd),"ND", nd)
                        .eq(StringUtils.isNotBlank(jg),"JG", jg)
                        .eq(StringUtils.isNotBlank(onesxlx),"ONESXLX", onesxlx)
                        .eq(StringUtils.isNotBlank(twosxlx),"TWOSXLX", twosxlx)
                        .likeLeft(StringUtils.isNotBlank(threesxlx),"THREESXLX", threesxlx)
                        .eq(StringUtils.isNotBlank(foursxlx),"FOURSXLX", foursxlx)
                        .orderByAsc("SXLXCODE")
                        .orderByAsc("ORDERNUM")
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils conditionQueryPage(Map<String, Object> params) {
        //根据文件名称查询
        String meetingDetailId  = (String)params.get("meetingDetailId");
        String attachId  = (String)params.get("attachId");
        String geocode  = (String)params.get("geocode");
        String jg  = (String)params.get("jg");
        String onesxlx  = (String)params.get("onesxlx");
        String twosxlx  = (String)params.get("twosxlx");
        String threesxlx  = (String)params.get("threesxlx");
        String foursxlx  = (String)params.get("foursxlx");
        String ordernum  = (String)params.get("ordernum");
        String nd  = (String)params.get("nd");
        String title  = (String)params.get("title");
        String author  = (String)params.get("author");
        String  startrq = (String)params.get("startrq");
        String  stoprq = (String)params.get("stoprq");
        String wh  = (String)params.get("wh");
        String qzh  = (String)params.get("qzh");
        String dh  = (String)params.get("dh");
        String bgqx  = (String)params.get("bgqx");
        String unitno  = (String)params.get("unitno");
        String damldm  = (String)params.get("damldm");
        String ngdw  = (String)params.get("ngdw");
        String wz  = (String)params.get("wz");
        String ngr  = (String)params.get("ngr");
        String bksm  = (String)params.get("bksm");
        String mlh  = (String)params.get("mlh");
        String zbkwh  = (String)params.get("zbkwh");
        String hhd  = (String)params.get("hhd");
        String dalx  = (String)params.get("dalx");
        String ys  = (String)params.get("ys");
        String mj  = (String)params.get("mj");
        String hh  = (String)params.get("hh");
        String flh  = (String)params.get("flh");
        String bz  = (String)params.get("bz");
        String zlcj  = (String)params.get("zlcj");
        String fwhty  = (String)params.get("fwhty");
        String xhqk  = (String)params.get("xhqk");
        String kfbs  = (String)params.get("kfbs");
        String gksx  = (String)params.get("gksx");
        String gjc  = (String)params.get("gjc");
        String sxlxcode  = (String)params.get("sxlxcode");
        List bgqxIdList=null;
        if(StringUtils.isNotBlank(bgqx)){
        bgqxIdList= bgqxDao.selectObjs(new QueryWrapper<BgqxEntity>().select("bgqx_id").eq("bgqx",bgqx));
        }

        IPage<MeetingDetailEntity> page = this.page(
                new Query<MeetingDetailEntity>().getPage(params),
                new QueryWrapper<MeetingDetailEntity>()
                        .like(StringUtils.isNotBlank(meetingDetailId),"meeting_detail_id", meetingDetailId)
                        .like(StringUtils.isNotBlank(attachId),"attach_id", attachId)
                        .like(StringUtils.isNotBlank(geocode),"geocode", geocode)
                        .like(StringUtils.isNotBlank(jg),"jg", jg)
                        .like(StringUtils.isNotBlank(onesxlx),"onesxlx", onesxlx)
                        .like(StringUtils.isNotBlank(twosxlx),"twosxlx", twosxlx)
                        .like(StringUtils.isNotBlank(threesxlx),"threesxlx", threesxlx)
                        .like(StringUtils.isNotBlank(foursxlx),"foursxlx", foursxlx)
                        .like(StringUtils.isNotBlank(ordernum),"ordernum", ordernum)
                        .like(StringUtils.isNotBlank(nd),"nd", nd)
                        .like(StringUtils.isNotBlank(title),"title", title)
                        .like(StringUtils.isNotBlank(author),"author", author)
                        .apply(StringUtils.isNotBlank(startrq),"rq >= to_date('" +startrq  + "','yyyy-MM-dd')")
                        .apply(StringUtils.isNotBlank(stoprq),"rq <= to_date('" +stoprq  + "','yyyy-MM-dd')")
                        .like(StringUtils.isNotBlank(wh),"wh", wh)
                        .like(StringUtils.isNotBlank(qzh),"qzh", qzh)
                        .like(StringUtils.isNotBlank(dh),"dh", dh)
                        .in(bgqxIdList!=null,"bgqx",bgqxIdList)
                        .like(StringUtils.isNotBlank(unitno),"unitno", unitno)
                        .like(StringUtils.isNotBlank(damldm),"damldm", damldm)
                        .like(StringUtils.isNotBlank(ngdw),"ngdw", ngdw)
                        .like(StringUtils.isNotBlank(wz),"wz", wz)
                        .like(StringUtils.isNotBlank(ngr),"ngr", ngr)
                        .like(StringUtils.isNotBlank(bksm),"bksm", bksm)
                        .like(StringUtils.isNotBlank(mlh),"mlh", mlh)
                        .like(StringUtils.isNotBlank(zbkwh),"zbkwh", zbkwh)
                        .like(StringUtils.isNotBlank(hhd),"hhd", hhd)
                        .like(StringUtils.isNotBlank(dalx),"dalx", dalx)
                        .like(StringUtils.isNotBlank(ys),"ys", ys)
                        .like(StringUtils.isNotBlank(mj),"mj", mj)
                        .like(StringUtils.isNotBlank(hh),"hh", hh)
                        .like(StringUtils.isNotBlank(flh),"flh", flh)
                        .like(StringUtils.isNotBlank(bz),"bz", bz)
                        .like(StringUtils.isNotBlank(zlcj),"zlcj", zlcj)
                        .like(StringUtils.isNotBlank(fwhty),"fwhty", fwhty)
                        .like(StringUtils.isNotBlank(xhqk),"xhqk", xhqk)
                        .like(StringUtils.isNotBlank(kfbs),"kfbs", kfbs)
                        .like(StringUtils.isNotBlank(gksx),"gksx", gksx)
                        .like(StringUtils.isNotBlank(gjc),"gjc", gjc)
                        .like(StringUtils.isNotBlank(sxlxcode),"sxlxcode", sxlxcode)
        );

        return new PageUtils(page);
    }


}